package com.spzx.channel.controller;

import com.spzx.channel.service.IndexService;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.product.api.domain.dto.BrandDto;
import com.spzx.product.api.domain.param.SkuQuery;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 频道页Controller
 *
 * @author atguigu
 * @date 2024-07-03
 */
@Tag(name = "频道页")
@RestController
public class IndexController extends BaseController {

    @Autowired
    private IndexService indexService;

    @Operation(summary = "商城频道首页")
    @GetMapping("/index")
    public AjaxResult index() {
        return success(indexService.getIndexData());
    }

    @Operation(description = "查询商品分类整体树形结构")
    @GetMapping("/category/tree")
    public AjaxResult categoryTree() {
        return success(indexService.categoryTree());
    }

    @Operation(description = "查询所有品牌信息")
    @GetMapping("/brand/getBrandAll")
    public AjaxResult getBrandAll() {
        return success(indexService.getBrandAll());
    }

    @Operation(description = "商品列表查询")
    @GetMapping("/list/skuList/{pageNum}/{pageSize}")
    public TableDataInfo skuList(@PathVariable("pageNum") Integer pageNum,
                                 @PathVariable("pageSize") Integer pageSize,
                                 SkuQuery query) {
        return getDataTable(indexService.skuList(pageNum, pageSize, query));
    }


    @Operation(description = "查看商品详情信息")
    @GetMapping("/item/{skuId}")
    public AjaxResult getItemBySkuId(@PathVariable("skuId") Long skuId) {
        return success(indexService.getItemBySkuId(skuId));
    }
}
